<template>
  <div class="box">
    <h1>品类详情</h1>
    <div>
      <!-- <el-button type="danger" @click="addshop">添加品类</el-button> -->
        <template>
          <el-table :data="typemain" border style="width: 100%">
            <el-table-column fixed prop="id" label="品类ID"></el-table-column>
            <el-table-column prop="name" label="名称"></el-table-column>
            <el-table-column fixed="right" label="操作">
              <template slot-scope="scope">
                  <el-button
                type="text"
                size="small"
                @click="onchange1(scope.row)"
                >编辑</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
  </div>
</template>

<script>
import { category2, gai } from "../../../http/http";
export default {
  data() {
    return {
      typemain: [],
    };
  },
  mounted() {
    // console.log(this.$route);

    category2(this.$route.query.id).then((res) => {
      //console.log(res.data.data);
      // console.log(res)
      this.typemain = res.data.data;
      // console.log(this.typemain)
    });
  },
  methods: {
    onchange1(val) {
      console.log(val);
      this.$prompt("请输入修改内容", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputValue: val.name,
      })
        .then(({ value }) => {
          gai({ categoryId: val.id, categoryName: value }).then((res) => {
            category2(this.$route.query.id).then((res2) => {
              console.log(res2);
              this.typemain = res2.data.data;
            });
            this.$message({
              type: "success",
              message: "修改成功",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消修改",
          });
        });
    },
  },
};
</script>

<style scoped>
.box {
  width: 80%;
  margin-left: 20%;
}
</style>